//战役回顾菜单

var reviewMenu = {
	showing : false,
	
	_upMenu : null,
	_downMenu : null,
	_reviewMenu : null,
	_menu : null,
	
	_noteLabelLeft : null,
	_noteLabelRight : null,
	_numberLabel : null,
	
	_number : 1,
	
	Initialize : function(){
		this.showing = false;
		this._upMenu = null;
		this._downMenu = null;
		this._reviewMenu = null;
		this._menu = null;
		this._noteLabelLeft = null;
		this._noteLabelRight = null;
		this._numberLabel = null;
		this._number = 1;
	},

	ShowUI : function(){
		if (this.showing)
			return;
		this.showing = true;
		
		var winSize = cc.director.getWinSize();

		this._noteLabelLeft = cc.LabelTTF.create("", "simhei", 48);
		campaignScene.canvaslayer.addChild(this._noteLabelLeft);
		
		this._noteLabelRight = cc.LabelTTF.create("", "simhei", 48);
		campaignScene.canvaslayer.addChild(this._noteLabelRight);

		if (campaign.time_ref.current_step < 1){
			this._noteLabelLeft.setString("当前是第一回合，没有战报可供查看");
			this._noteLabelLeft.attr({x : 0.5 * winSize.width, y : 0.5 * winSize.height});
		}else{
			this._noteLabelLeft.setString("回顾过去");
			this._upMenu = this._CreateVerticalButton("↑", 0,	0, reviewMenu._OnClickUpNumber);
			this._numberLabel = cc.LabelTTF.create("" + this._number, "simhei", 48);
			this._downMenu = this._CreateVerticalButton("↓", 0,	0, reviewMenu._OnClickDownNumber);
			this._noteLabelRight.setString("个回合的战报");
			this._reviewMenu = this._CreateNormalButton("查看", 0, 0, reviewMenu._OnReviewClick);

			this._number = 1;
			this._RefreshNumberUpDownEnable();
			
			var arrangeNodes = [this._noteLabelLeft, this._upMenu, this._numberLabel, this._downMenu, this._noteLabelRight, this._reviewMenu];
			ArrangeHorizontal(0.5 * winSize.width, 0.5 * winSize.height, 0.015 * winSize.width, arrangeNodes);

			this._menu = new cc.Menu(this._upMenu, this._downMenu, this._reviewMenu);
			this._menu.attr({x: 0, y: 0});

			campaignScene.canvaslayer.addChild(this._menu);
			campaignScene.canvaslayer.addChild(this._numberLabel);
		}
	},
	
	_CreateNormalButton : function(text,xpos,ypos,callback){
		var button = new cc.MenuItemImage(resource.ctrlbtnNormal_png,resource.ctrlbtnDown_png, resource.ctrlbtnDisable_png, callback, this);
		button.setPosition(xpos, ypos);
		var label = cc.LabelTTF.create(text, "simhei", 28);
		label.setPosition(button.width * 0.5, button.height * 0.5);
		label.setColor(cc.color(0,0,0));
		button.addChild(label);
		return button;
	},
	
	_CreateVerticalButton : function(text,xpos,ypos,callback){
		var button = new cc.MenuItemImage(resource.ctrlbtnNormalV_png,resource.ctrlbtnDownV_png, resource.ctrlbtnDisableV_png, callback, this);
		button.setPosition(xpos, ypos);
		var label = cc.LabelTTF.create(text, "simhei", 28);
		label.setPosition(button.width * 0.5, button.height * 0.5);
		label.setColor(cc.color(0,0,0));
		button.addChild(label);
		return button;
	},

	HideUI : function(){
		if (this.showing == false)
			return;
		this.showing = false;
		
		if (this._menu != null){
			this._menu.removeFromParent();
			this._menu = null;
		}
		if (this._numberLabel != null){
			this._numberLabel.removeFromParent();
			this._numberLabel = null;
		}
		if (this._noteLabelLeft != null){
			this._noteLabelLeft.removeFromParent();
			this._noteLabelLeft = null;
		}
		if (this._noteLabelRight != null){
			this._noteLabelRight.removeFromParent();
			this._noteLabelRight = null;
		}
		
		if (reviewLoop.playing){
			reviewLoop.FinishReview();
		}
	},

	_OnReviewClick : function(sender){
		this.HideUI();
		reviewLoop.Review(campaign.time_ref.current_step - this._number);
	},

	_OnClickUpNumber : function(sender){
		this._numberLabel.setString("" + (++this._number));
		this._RefreshNumberUpDownEnable();
	},

	_OnClickDownNumber : function(sender){
		this._numberLabel.setString("" + (--this._number));
		this._RefreshNumberUpDownEnable();
	},

	_RefreshNumberUpDownEnable : function(){
		this._downMenu.enabled = this._number > 1;
		this._upMenu.enabled = this._number < campaign.time_ref.current_step;
	}
};

control.onBattleReviewClick = function(){
	if (reviewMenu.showing == false){
		if (reviewLoop.playing){
			reviewLoop.FinishReview();
		}else{
			SetAllManipulateEnable(false);
			control.warInfoMenu.enabled = true;
			control.battleReviewMenu.enabled = true;
	
			reviewMenu.ShowUI();
			campaignScene.canvaslayer.show(true);
		}
	}else{
		SetAllManipulateEnable(true);

		reviewMenu.HideUI();
		campaignScene.canvaslayer.hide(false);
	}
};